package secondBrush.string;

public class E06Leetcode28 {
    public int strStr(String haystack, String needle) {
        int hLength = haystack.length(), nLength = needle.length();
        char[] hCharArray = haystack.toCharArray();
        char[] nCharArray = needle.toCharArray();

        //遍历
        for (int i = 0; i < hLength - nLength + 1; i++) {

            int a = i, b = 0;
            while (b < nLength && hCharArray[a] == nCharArray[b]) {
                a++;
                b++;

            }
            if (b == nLength) {
                return i;
            }


        }
        return -1;


    }

    public static void main(String[] args) {
        String haystack = "a";
        String needle = "a";
        E06Leetcode28 e06Leetcode28 = new E06Leetcode28();
        System.out.println(e06Leetcode28.strStr(haystack, needle));

    }

}
